rtc23 2.2.1
Loading...
Searching...
No Matches
rtc23.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef RTC23_H
29#define RTC23_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
59
64
69
74#define RTC23_REG_HUNDREDTHS 0x00
75#define RTC23_REG_SECONDS 0x01
76#define RTC23_REG_MINUTES 0x02
77#define RTC23_REG_HOURS 0x03
78#define RTC23_REG_DATE 0x04
79#define RTC23_REG_MONTHS 0x05
80#define RTC23_REG_YEARS 0x06
81#define RTC23_REG_WEEKDAYS 0x07
82#define RTC23_REG_HUNDREDTHS_ALARM 0x08
83#define RTC23_REG_SECONDS_ALARM 0x09
84#define RTC23_REG_MINUTES_ALARM 0x0A
85#define RTC23_REG_HOURS_ALARM 0x0B
86#define RTC23_REG_DATE_ALARM 0x0C
87#define RTC23_REG_MONTHS_ALARM 0x0D
88#define RTC23_REG_WEEKDAYS_ALARM 0x0E
89#define RTC23_REG_STATUS 0x0F
90#define RTC23_REG_CONTROL1 0x10
91#define RTC23_REG_CONTROL2 0x11
92#define RTC23_REG_INT_MASK 0x12
93#define RTC23_REG_SQW 0x13
94#define RTC23_REG_CAL_XT 0x14
95#define RTC23_REG_CAL_RC_HI 0x15
96#define RTC23_REG_CAL_RC_LOW 0x16
97#define RTC23_REG_SLEEP_CONTROL 0x17
98#define RTC23_REG_TIMER_CONTROL 0x18
99#define RTC23_REG_TIMER 0x19
100#define RTC23_REG_TIMER_INITIAL 0x1A
101#define RTC23_REG_WDT 0x1B
102#define RTC23_REG_OSC_CONTROL 0x1C
103#define RTC23_REG_OSC_STATUS 0x1D
104#define RTC23_REG_CONFIGURATION_KEY 0x1F
105#define RTC23_REG_TRICKLE 0x20
106#define RTC23_REG_BREF_CONTROL 0x21
107#define RTC23_REG_AFCTRL 0x26
108#define RTC23_REG_BATMODE_IO 0x27
109#define RTC23_REG_ID0 0x28
110#define RTC23_REG_ID1 0x29
111#define RTC23_REG_ID2 0x2A
112#define RTC23_REG_ID3 0x2B
113#define RTC23_REG_ID4 0x2C
114#define RTC23_REG_ID5 0x2D
115#define RTC23_REG_ID6 0x2E
116#define RTC23_REG_ASTAT 0x2F
117#define RTC23_REG_OCTRL 0x30
118#define RTC23_REG_EXTENSION_ADDRESS 0x3F
119#define RTC23_REG_RAM 0x40
120 // rtc23_reg
122
127
132
137#define RTC23_MONDAY 0x00
138#define RTC23_TUESDAY 0x01
139#define RTC23_WEDNESDAY 0x02
140#define RTC23_THURSDAY 0x03
141#define RTC23_FRIDAY 0x04
142#define RTC23_SATURDAY 0x05
143#define RTC23_SUNDAY 0x06
144
149#define RTC23_DEVICE_ID 0x18
150
159#define RTC23_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
160#define RTC23_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
161 // rtc23_set
163
168
173
178#define RTC23_MAP_MIKROBUS( cfg, mikrobus ) \
179 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
180 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
181 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
182 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
183 cfg.psw = MIKROBUS( mikrobus, MIKROBUS_AN ); \
184 cfg.wdi = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
185 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
186 // rtc23_map // rtc23
189
194typedef struct
195{
196 // Output pins
197 digital_out_t wdi;
198
199 // Input pins
200 digital_in_t psw;
201 digital_in_t int_pin;
202
203 // Modules
204 spi_master_t spi;
205
206 pin_name_t chip_select;
207
208} rtc23_t;
209
214typedef struct
215{
216 // Communication gpio pins
217 pin_name_t miso;
218 pin_name_t mosi;
219 pin_name_t sck;
220 pin_name_t cs;
221
222 // Additional gpio pins
223 pin_name_t wdi;
224 pin_name_t psw;
225 pin_name_t int_pin;
226
227 // static variable
228 uint32_t spi_speed;
229 spi_master_mode_t spi_mode;
230 spi_master_chip_select_polarity_t cs_polarity;
231
233
239typedef struct
240{
242 uint8_t second;
243 uint8_t minute;
244 uint8_t hour;
245
247
253typedef struct
254{
255 uint8_t day_of_week;
256 uint8_t day;
257 uint8_t month;
258 uint8_t year;
259
261
266typedef enum
267{
270
272
278
289
303err_t rtc23_init ( rtc23_t *ctx, rtc23_cfg_t *cfg );
304
319err_t rtc23_write_regs ( rtc23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
320
335err_t rtc23_read_regs ( rtc23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
336
349err_t rtc23_write_reg ( rtc23_t *ctx, uint8_t reg, uint8_t data_in );
350
363err_t rtc23_read_reg ( rtc23_t *ctx, uint8_t reg, uint8_t *data_out );
364
374void rtc23_set_wdi_pin ( rtc23_t *ctx, uint8_t state );
375
384uint8_t rtc23_get_psw_pin ( rtc23_t *ctx );
385
394uint8_t rtc23_get_int_pin ( rtc23_t *ctx );
395
407
420err_t rtc23_set_time ( rtc23_t *ctx, rtc23_time_t *time );
421
435
448err_t rtc23_set_date ( rtc23_t *ctx, rtc23_date_t *date );
449
463
464#ifdef __cplusplus
465}
466#endif
467#endif // RTC23_H
468 // rtc23
470
471// ------------------------------------------------------------------------ END
err_t rtc23_set_time(rtc23_t *ctx, rtc23_time_t *time)
RTC 23 set time function.
void rtc23_set_wdi_pin(rtc23_t *ctx, uint8_t state)
RTC 23 set WDI pin function.
uint8_t rtc23_get_int_pin(rtc23_t *ctx)
RTC 23 get INT pin function.
err_t rtc23_set_date(rtc23_t *ctx, rtc23_date_t *date)
RTC 23 set date function.
err_t rtc23_init(rtc23_t *ctx, rtc23_cfg_t *cfg)
RTC 23 initialization function.
err_t rtc23_read_reg(rtc23_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 23 read reg function.
err_t rtc23_check_communication(rtc23_t *ctx)
RTC 23 check communication function.
uint8_t rtc23_get_psw_pin(rtc23_t *ctx)
RTC 23 get PSW pin function.
err_t rtc23_read_regs(rtc23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 23 read regs function.
err_t rtc23_write_reg(rtc23_t *ctx, uint8_t reg, uint8_t data_in)
RTC 23 write reg function.
void rtc23_cfg_setup(rtc23_cfg_t *cfg)
RTC 23 configuration object setup function.
err_t rtc23_read_date(rtc23_t *ctx, rtc23_date_t *date)
RTC 23 read date function.
err_t rtc23_write_regs(rtc23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 23 write regs function.
err_t rtc23_read_time(rtc23_t *ctx, rtc23_time_t *time)
RTC 23 read time function.
rtc23_return_value_t
RTC 23 Click return value data.
Definition rtc23.h:267
@ RTC23_ERROR
Definition rtc23.h:269
@ RTC23_OK
Definition rtc23.h:268
This file contains SPI specific macros, functions, etc.
RTC 23 Click configuration object.
Definition rtc23.h:215
pin_name_t psw
Definition rtc23.h:224
pin_name_t wdi
Definition rtc23.h:223
spi_master_chip_select_polarity_t cs_polarity
Definition rtc23.h:230
pin_name_t sck
Definition rtc23.h:219
spi_master_mode_t spi_mode
Definition rtc23.h:229
pin_name_t mosi
Definition rtc23.h:218
uint32_t spi_speed
Definition rtc23.h:228
pin_name_t int_pin
Definition rtc23.h:225
pin_name_t miso
Definition rtc23.h:217
pin_name_t cs
Definition rtc23.h:220
RTC 23 Click date object.
Definition rtc23.h:254
uint8_t month
Definition rtc23.h:257
uint8_t day
Definition rtc23.h:256
uint8_t year
Definition rtc23.h:258
uint8_t day_of_week
Definition rtc23.h:255
RTC 23 Click context object.
Definition rtc23.h:195
spi_master_t spi
Definition rtc23.h:204
digital_in_t psw
Definition rtc23.h:200
digital_in_t int_pin
Definition rtc23.h:201
pin_name_t chip_select
Definition rtc23.h:206
digital_out_t wdi
Definition rtc23.h:197
RTC 23 Click time object.
Definition rtc23.h:240
uint8_t second
Definition rtc23.h:242
uint8_t minute
Definition rtc23.h:243
uint8_t second_100th
Definition rtc23.h:241
uint8_t hour
Definition rtc23.h:244